package com.numberone.system.service.impl;

import com.numberone.common.support.Convert;
import com.numberone.system.domain.Industry;
import com.numberone.system.mapper.IndustryMapper;
import com.numberone.system.service.IIndustryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
 * 行业 服务层实现
 * 
 * @author numberone
 * @date 2020-09-28
 */
@Service
public class IndustryServiceImpl implements IIndustryService
{
	@Autowired
	private IndustryMapper industryMapper;

	/**
     * 查询行业信息
     * 
     * @param id 行业ID
     * @return 行业信息
     */
    @Override
	public Industry selectIndustryById(Long id)
	{
	    return industryMapper.selectIndustryById(id);
	}

	/**
	 * 查询行业列表
	 *
	 * @return 行业集合
	 */
	@Override
	public List<Industry> selectIndustryList()
	{
		List<Industry> industrieFather = industryMapper.selectIndustryFather();
		List<Industry> industryChild = industryMapper.selectIndustryChild();
		for (Industry i : industrieFather)
		{
			List<Industry> list = new LinkedList<>();
			for (Industry j : industryChild)
			{
				if (j.getPid() == i.getId())
				{
					list.add(j);
				}
			}
			i.setChild(list);
		}
		return industrieFather;
	}

	/**
     * 查询行业列表
     * 
     * @param industry 行业信息
     * @return 行业集合
     */
	@Override
	public List<Industry> selectIndustryList(Industry industry)
	{
	    return industryMapper.selectIndustryList(industry);
	}
	
    /**
     * 新增行业
     * 
     * @param industry 行业信息
     * @return 结果
     */
	@Override
	public int insertIndustry(Industry industry)
	{
	    return industryMapper.insertIndustry(industry);
	}
	
	/**
     * 修改行业
     * 
     * @param industry 行业信息
     * @return 结果
     */
	@Override
	public int updateIndustry(Industry industry)
	{
	    return industryMapper.updateIndustry(industry);
	}

	/**
     * 删除行业对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteIndustryByIds(String ids)
	{
		return industryMapper.deleteIndustryByIds(Convert.toStrArray(ids));
	}
	
}
